package com.monitor.util;


import com.alibaba.druid.util.StringUtils;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

public class DataUtil {
	/**
	  * 获取现在时间
	  * 
	  * @return 返回时间类型 yyyy-MM-dd HH:mm:ss
	  */
	 public static Date getNowDate() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  String dateString = formatter.format(currentTime);
	  ParsePosition pos = new ParsePosition(8);
	  Date currentTime_2 = formatter.parse(dateString, pos);
	  return currentTime_2;
	 }

	 /**
	  * 获取现在时间
	  * 
	  * @return返回短时间格式 yyyy-MM-dd
	  */
	 public static Date getNowDateShort() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	  String dateString = formatter.format(currentTime);
	  ParsePosition pos = new ParsePosition(8);
	  Date currentTime_2 = formatter.parse(dateString, pos);
	  return currentTime_2;
	 }

	 /**
	  * 获取现在时间
	  * 
	  * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
	  */
	 public static String getStringDate() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  String dateString = formatter.format(currentTime);
	  return dateString;
	 }
	 
	 /**
	  * 获取指定时间
	  * 
	  * @return返回字符串格式 yyyyMMdd
	  */
	 public static String getStringDate(String time) {
	  String dateString = time.replace("-", "");
	  return dateString;
	 }

	 /**
	  * 获取现在时间
	  * 
	  * @return 返回短时间字符串格式yyyy-MM-dd
	  */
	 public static String getStringDateShort() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	  String dateString = formatter.format(currentTime);
	  return dateString;
	 }

	 /**
	  * 获取时间 小时:分;秒 HH:mm:ss
	  * 
	  * @return
	  */
	 public static String getTimeShort() {
	  SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
	  Date currentTime = new Date();
	  String dateString = formatter.format(currentTime);
	  return dateString;
	 }

	 /**
	  * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
	  * 
	  * @param strDate
	  * @return
	  */
	 public static Date strToDateLong(String strDate) {
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  ParsePosition pos = new ParsePosition(0);
	  Date strtodate = formatter.parse(strDate, pos);
	  return strtodate;
	 }

	 /**
	  * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
	  * 
	  * @param dateDate
	  * @return
	  */
	 public static String dateToStrLong(Date dateDate) {
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  String dateString = formatter.format(dateDate);
	  return dateString;
	 }

	 /**
	  * 将短时间格式时间转换为字符串 yyyy-MM-dd
	  * 
	  * @param dateDate
	  * @param
	  * @return
	  */
	 public static String dateToStr(Date dateDate) {
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	  String dateString = formatter.format(dateDate);
	  return dateString;
	 }

	 /**
	  * 将短时间格式字符串转换为时间 yyyy-MM-dd 
	  * 
	  * @param strDate
	  * @return
	  */
	 public static Date strToDate(String strDate) {
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
	  ParsePosition pos = new ParsePosition(0);
	  if(StringUtils.isEmpty(strDate))
	      return null;
	  Date strtodate = formatter.parse(strDate, pos);
	  return strtodate;
	 }

	 /**
	  * 得到现在时间
	  * 
	  * @return
	  */
	 public static Date getNow() {
	  Date currentTime = new Date();
	  return currentTime;
	 }

	 /**
	  * 提取一个月中的最后一天
	  * 
	  * @param day
	  * @return
	  */
	 public static Date getLastDate(long day) {
	  Date date = new Date();
	  long date_3_hm = date.getTime() - 3600000 * 34 * day;
	  Date date_3_hm_date = new Date(date_3_hm);
	  return date_3_hm_date;
	 }

	 /**
	  * 得到现在时间
	  * 
	  * @return 字符串 yyyyMMdd HHmmss
	  */
	 public static String getStringToday() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
	  String dateString = formatter.format(currentTime);
	  return dateString;
	 }

	 /**
	  * 得到现在小时
	  */
	 public static String getHour() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  String dateString = formatter.format(currentTime);
	  String hour;
	  hour = dateString.substring(11, 13);
	  return hour;
	 }

	 /**
	  * 得到现在分钟
	  * 
	  * @return
	  */
	 public static String getTime() {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  String dateString = formatter.format(currentTime);
	  String min;
	  min = dateString.substring(14, 16);
	  return min;
	 }

	 /**
	  * 根据用户传入的时间表示格式，返回当前时间的格式 如果是yyyyMMdd，注意字母y不能大写。
	  * 
	  * @param sformat
	  *            yyyyMMddhhmmss
	  * @return
	  */
	 public static String getUserDate(String sformat) {
	  Date currentTime = new Date();
	  SimpleDateFormat formatter = new SimpleDateFormat(sformat);
	  String dateString = formatter.format(currentTime);
	  return dateString;
	 }

	 /**
	  * 二个小时时间间的差值,必须保证二个时间都是"HH:MM"的格式，返回字符型的分钟
	  */
	 public static String getTwoHour(String st1, String st2) {
	  String[] kk = null;
	  String[] jj = null;
	  kk = st1.split(":");
	  jj = st2.split(":");
	  if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0]))
	   return "0";
	  else {
	   double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) / 60;
	   double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) / 60;
	   if ((y - u) > 0)
	    return y - u + "";
	   else
	    return "0";
	  }
	 }

	 
	 /**
	  * 获取上一月的日期
	  * 
	  * @param
	  *            
	  */
	 public static String getAfterMonth() {
		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 Calendar c = Calendar.getInstance();
		//过去一月
		 c.setTime(new Date());
		 c.add(Calendar.MONTH, -1);
	     Date m = c.getTime();
	     String mon = format.format(m);
	     System.out.println("过去一个月："+mon);      
	     return mon;   
	 }
	 
	 /**
	  * 获取上周的日期
	  * 
	  * @param
	  *            
	  */
	 public static Map<String,String> getAfterWeek() {
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 Map<String,String> map=new HashMap<String,String>();
		 Calendar calendar1 = Calendar.getInstance();  
	     Calendar calendar2 = Calendar.getInstance();  
	     int dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK) - 1;  
	     int offset1 = 1 - dayOfWeek;  
	     int offset2 = 7 - dayOfWeek;  
	     calendar1.add(Calendar.DATE, offset1 - 7);  
	     calendar2.add(Calendar.DATE, offset2 - 7);  
	     // System.out.println(sdf.format(calendar1.getTime()));// last Monday  
	     String lastBeginDate = sdf.format(calendar1.getTime());  
	     // System.out.println(sdf.format(calendar2.getTime()));// last Sunday  
	     String lastEndDate = sdf.format(calendar2.getTime());  
	     map.put("lastBeginDate", lastBeginDate);
	     map.put("lastEndDate", lastEndDate);
	     return map;  
	 }
	 
	 /**
	  * 获取当周的日期
	  * 
	  * @param 
	  *            
	  */
	public static Map<String,String> getTimeInterval(Date date) {
		Map<String,String> map=new HashMap<String,String>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
	     cal.setTime(date);
	     // 判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
	     int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
	     if (1 == dayWeek) {
	        cal.add(Calendar.DAY_OF_MONTH, -1);
	     }
	     // System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
	     // 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
	     cal.setFirstDayOfWeek(Calendar.MONDAY);
	     // 获得当前日期是一个星期的第几天
	     int day = cal.get(Calendar.DAY_OF_WEEK);
	     // 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
	     cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
	     String imptimeBegin = sdf.format(cal.getTime());
	     // System.out.println("所在周星期一的日期：" + imptimeBegin);
	     cal.add(Calendar.DATE, 6);
	     String imptimeEnd = sdf.format(cal.getTime());
	     // System.out.println("所在周星期日的日期：" + imptimeEnd);
	     System.out.println(imptimeBegin);
	     System.out.println(imptimeEnd);
	     map.put("imptimeBegin", imptimeBegin);
	     map.put("imptimeEnd", imptimeEnd);
	     return map;
	}
	 
	 /**
	  * 获取当月的第一天和最后一天
	  * 
	  * @param 
	  *            
	  */
	 public static Map<String,String> getNowMonthOneDay() {
		 Map<String,String> map=new HashMap<String,String>();
		 Calendar cale = Calendar.getInstance();    
		// 获取当月第一天和最后一天
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			String firstday, lastday;
			// 获取前月的第一天
			cale = Calendar.getInstance();
			cale.add(Calendar.MONTH, 0);
			cale.set(Calendar.DAY_OF_MONTH, 1);
			firstday = format.format(cale.getTime());
			// 获取前月的最后一天
			cale = Calendar.getInstance();
			cale.add(Calendar.MONTH, 1);
			cale.set(Calendar.DAY_OF_MONTH, 0);
			lastday = format.format(cale.getTime());
			System.out.println("本月第一天和最后一天分别是 ： " + firstday + " and " + lastday);
			map.put("firstday", firstday);
			map.put("lastday", lastday);
		return 	map;
	 }
	 
	
	 
	 
	 
	 /**
	  * 得到二个日期间的间隔天数
	  */
	 public static String getTwoDay(String sj1, String sj2) {
	  SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
	  long day = 0;
	  try {
	   Date date = myFormatter.parse(sj1);
	   Date mydate = myFormatter.parse(sj2);
	   day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
	  } catch (Exception e) {
	   return "";
	  }
	  return day + "";
	 }

	 /**
	  * 时间前推或后推分钟,其中JJ表示分钟.
	  */
	 public static String getPreTime(Date sj1, String jj) {
	  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  String mydate1 = "";
	  try {
	   Date date1 = sj1;
	   long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
	   date1.setTime(Time * 1000);
	   mydate1 = format.format(date1);
	  } catch (Exception e) {
	  }
	  return mydate1;
	 }

	 /**
	  * 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
	  */
	 public static String getNextDay(String nowdate, String delay) {
	  try{
	  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	  String mdate = "";
	  Date d = strToDate(nowdate);
	  long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60;
	  d.setTime(myTime * 1000);
	  mdate = format.format(d);
	  return mdate;
	  }catch(Exception e){
	   return "";
	  }
	 }

	 /**
	  * 判断是否润年
	  * 
	  * @param ddate
	  * @return
	  */
	 public static boolean isLeapYear(String ddate) {

	  /**
	   * 详细设计： 1.被400整除是闰年，否则： 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年
	   * 3.能被4整除同时能被100整除则不是闰年
	   */
	  Date d = strToDate(ddate);
	  GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
	  gc.setTime(d);
	  int year = gc.get(Calendar.YEAR);
	  if ((year % 400) == 0)
	   return true;
	  else if ((year % 4) == 0) {
	   if ((year % 100) == 0)
	    return false;
	   else
	    return true;
	  } else
	   return false;
	 }

	 /**
	  * 返回美国时间格式 26 Apr 2006
	  * 
	  * @param str
	  * @return
	  */
	 public static String getEDate(String str) {
	  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	  ParsePosition pos = new ParsePosition(0);
	  Date strtodate = formatter.parse(str, pos);
	  String j = strtodate.toString();
	  String[] k = j.split(" ");
	  return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
	 }

	 /**
	  * 获取一个月的最后一天
	  * 
	  * @param dat
	  * @return
	  */
	 public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd
	  String str = dat.substring(0, 8);
	  String month = dat.substring(5, 7);
	  int mon = Integer.parseInt(month);
	  if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) {
	   str += "31";
	  } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
	   str += "30";
	  } else {
	   if (isLeapYear(dat)) {
	    str += "29";
	   } else {
	    str += "28";
	   }
	  }
	  return str;
	 }

	 /**
	  * 判断二个时间是否在同一个周
	  * 
	  * @param date1
	  * @param date2
	  * @return
	  */
	 public static boolean isSameWeekDates(Date date1, Date date2) {
	  Calendar cal1 = Calendar.getInstance();
	  Calendar cal2 = Calendar.getInstance();
	  cal1.setTime(date1);
	  cal2.setTime(date2);
	  int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
	  if (0 == subYear) {
	   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
	    return true;
	  } else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) {
	   // 如果12月的最后一周横跨来年第一周的话则最后一周即算做来年的第一周
	   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
	    return true;
	  } else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) {
	   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
	    return true;
	  }
	  return false;
	 }

	 /**
	  * 产生周序列,即得到当前时间所在的年度是第几周
	  * 
	  * @return
	  */
	 public static String getSeqWeek() {
	  Calendar c = Calendar.getInstance(Locale.CHINA);
	  String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR));
	  if (week.length() == 1)
	   week = "0" + week;
	  String year = Integer.toString(c.get(Calendar.YEAR));
	  return year + week;
	 }

	 

	 /**
	  * 两个时间之间的天数
	  * 
	  * @param date1
	  * @param date2
	  * @return
	  */
	 public static long getDays(String date1, String date2) {
	  if (date1 == null || date1.equals(""))
	   return 0;
	  if (date2 == null || date2.equals(""))
	   return 0;
	  // 转换为标准时间
	  SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
	  Date date = null;
	  Date mydate = null;
	  try {
	   date = myFormatter.parse(date1);
	   mydate = myFormatter.parse(date2);
	  } catch (Exception e) {
	  }
	  long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
	  return day;
	 }

	

	 /**
	  * 取得数据库主键 生成格式为yyyymmddhhmmss+k位随机数
	  * 
	  * @param k
	  *            表示是取几位随机数，可以自己定
	  */

	 public static String getNo(int k) {

	  return getUserDate("yyyyMMddhhmmss") + getRandom(k);
	 }

	 /**
	  * 返回一个随机数
	  * 
	  * @param i
	  * @return
	  */
	 public static String getRandom(int i) {
	  Random jjj = new Random();
	  // int suiJiShu = jjj.nextInt(9);
	  if (i == 0)
	   return "";
	  String jj = "";
	  for (int k = 0; k < i; k++) {
	   jj = jj + jjj.nextInt(9);
	  }
	  return jj;
	 }

	 /**
	  * 
	  * @param date
	  */
	 public static boolean RightDate(String date) {

	  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	  ;
	  if (date == null)
	   return false;
	  if (date.length() > 10) {
	   sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	  } else {
	   sdf = new SimpleDateFormat("yyyy-MM-dd");
	  }
	  try {
	   sdf.parse(date);
	  } catch (ParseException pe) {
	   return false;
	  }
	  return true;
	 }

    /**
     * 返回当前时间前后一个半月的时间和当年的时间
     *
     * @param
     * @return
     */
    public static Map<String,Object> getThreeMonth() {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");//格式化为2017-10
        Map<String,Object> map=new HashMap<String,Object>();
        Calendar c = Calendar.getInstance(Locale.CHINA);
        //前一个月
        c.add(Calendar.MONTH,-1);
        c.set(Calendar.DAY_OF_MONTH,1);
        Date starDate = c.getTime();//得到时间赋给Data
        String stardtr = formatter.format(starDate);//使用格式化Data
        map.put("afterDate",stardtr);
        System.out.println(stardtr);
        //后一个月
        c = Calendar.getInstance(Locale.CHINA);
        c.add(Calendar.MONTH,2);
        c.set(Calendar.DAY_OF_MONTH,0);
        Date endDate = c.getTime();//得到时间赋给Data
        String enddtr = formatter.format(endDate);//使用格式化Data
        map.put("beforeDate",enddtr);
        System.out.println(enddtr);
        //一年
        c = Calendar.getInstance(Locale.CHINA);
        c.set(Calendar.MONTH,0);
        c.set(Calendar.DAY_OF_MONTH,1);
        Date starYearDate = c.getTime();//得到时间赋给Data
        String starYeardtr = formatter.format(starYearDate);//使用格式化Data
        map.put("starYeardtr",starYeardtr);
        System.out.println(starYeardtr);
        c = Calendar.getInstance(Locale.CHINA);
        c.set(Calendar.MONTH,12);
        c.set(Calendar.DAY_OF_MONTH,1);
        Date endYearDate = c.getTime();//得到时间赋给Data
        String endYeardtr = formatter.format(endYearDate);//使用格式化Data
        map.put("endYeardtr",endYeardtr);
        System.out.println(endYeardtr);
        return map;
    }

    /**
     * 返回日期所属月份第几周
     *
     * @param strDate
     * @return
     */
    public static Integer getFewOfDateForMonth(String strDate) throws ParseException{
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = format.parse(strDate);
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
       //System.out.println(calendar.get(Calendar.WEEK_OF_MONTH));
        return calendar.get(Calendar.WEEK_OF_MONTH);
    }

    /**
     * 返回一年中的十二个月份
     *
     * @param year
     * @return  String []
     */
    public static String [] geMonthOfYear(int year) throws ParseException{
        String [] months={year+"-01",year+"-02",year+"-03",year+"-04",year+"-05",year+"-06",year+"-07",year+"-08",year+"-09",
                 year+"-10",year+"-11",year+"-12"};
        return months;
    }

    /**
     * 返回一年中的第一天开始时间和最后一天结束时间
     *
     * @param year
     * @return  String []
     */
    public static String [] geDayOfYear(int year) throws ParseException{
        String [] months={year-1+"-12-31 23:59:59",year+1+"-01-01 00:00:00"};
        return months;
    }

    /**
     * 返回一月中有多少周
     *
     * @param
     * @return
     */
    public static Integer getWeekNum(String strDate) throws ParseException{

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        Date date = format.parse(strDate);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Integer weekNum=calendar.getActualMaximum(Calendar.WEEK_OF_MONTH);

        return weekNum;
    }

	 public static void main(String[] args) throws Exception {
              /*getFewOfDateForMonth("2017-7-19 10:25:21");
              String str="2017-05-09 32:45:45";
              System.out.println(str.substring(0,7));
              for(String minthStr:geMonthOfYear(2018)){
                  System.out.println(minthStr);
              }*/
              /*geDayOfYear(2018);
              Map<String,Object> map=new HashMap<String,Object>();
              map.put("ss11","sss");
              map.put("ss","ghyhjiko");
              System.out.println(map.get("ss"));

              for(String key : map.keySet()){
                  System.out.println(key);
              }*/
              /*Calendar c = Calendar.getInstance();
              c.set(Calendar.YEAR, 2010); // 2010年
              c.set(Calendar.MONTH, 5); // 6 月
              System.out.println("------------" + c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月的天数和周数-------------");
              System.out.println("天数：" + c.getActualMaximum(Calendar.DAY_OF_MONTH));
              System.out.println("周数：" + c.getActualMaximum(Calendar.WEEK_OF_MONTH));*/
              //getWeekNum("2018-12");
              /*Calendar c = Calendar.getInstance();
              c.set(Calendar.YEAR, 2018); // 2010年
              c.set(Calendar.MONTH, 7); // 8 月
              c.set(Calendar.DAY_OF_MONTH, 5); // 8 月
              getTimeInterval(c.getTime());*/
              /*SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
              Map<String,String> map=DataUtil.getTimeInterval(sdf.parse("2018-08-06"));*/
              /*List<Integer> numbers=Arrays.asList(-3, -21, -1, 0 ,1,2,3, 4,5, 6,7,8, 9,1,2,3, 4,5,6 ,7 ,8 ,9,5);
              List<Integer> sum=numbers.stream().distinct().collect(Collectors.toList());
              System.out.println(sum.toString().substring(1,sum.toString().length()-1).replace(" ",""));
		 System.out.println(BlankUtil.listToString(sum));*/
             /*List<Object> objectList=new ArrayList<Object>();
             Object [] objects1={"2013/1/24", 2320.26,2320.26,2287.3,2362.94};
             Object [] objects2={"2013/1/240", 2320.26,2320.26,2287.3,2362.94};
             objectList.add(objects1);objectList.add(objects2);
             System.out.println(objectList);*/
		 System.out.println(DataUtil.TimeDifference2("2007-01-01 11:11:01","2008-01-02 11:11:02"));

          }

	 //获得当前月第一天
	 public static String getMonFirst() {
		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 
	        
	        //获取前月的第一天
	        Calendar   cal_1=Calendar.getInstance();//获取当前日期 
	        cal_1.add(Calendar.MONTH, -1);
	        cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
	        String firstDay = format.format(cal_1.getTime());
	        System.out.println("-----1------firstDay:"+firstDay);
	        return firstDay;
	 }
	public static String TimeDifference2(String startDate,String endDate) throws  Exception {
	 int days; //天数
	 int hours; //时
	 int minutes; //分
	 int seconds; //秒

//通过字符串创建两个日期对象

		//注意：SimpleDateFormat构造函数的样式与strDate的样式必须相符
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


			Date firstDate=simpleDateFormat.parse(endDate);
			Date secondDate=simpleDateFormat.parse(startDate);


//得到两个日期对象的总毫秒数
			long firstDateMilliSeconds = firstDate.getTime();
			long secondDateMilliSeconds = secondDate.getTime();
//得到两者之差
			long firstMinusSecond = firstDateMilliSeconds - secondDateMilliSeconds;
//毫秒转为秒
			long milliSeconds = firstMinusSecond;
			int totalSeconds = (int)(milliSeconds / 1000);
//得到总天数
			days = totalSeconds / (3600*24);
			int days_remains = totalSeconds % (3600*24);
//得到总小时数
			hours = days_remains / 3600;
			int remains_hours = days_remains % 3600;
//得到分种数
			minutes = remains_hours / 60;
//得到总秒数
			seconds = remains_hours % 60;
//打印结果
//第一个比第二个多32天2小时3分4秒
			System.out.print("第二个比第一个多");
			System.out.println(days+"天"+hours+"小时"+minutes+"分"+seconds+"秒");

			return days+"天"+hours+"小时"+minutes+"分"+seconds+"秒";
	}


}
